from celery import Celery
from django.conf import settings
from django.core.mail import send_mail

import time

# import os
# import django
#
# os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'fruit.settings')
# django.setup()


app = Celery('celery_tasks.tasks', broker='redis://127.0.0.1/1')


@app.task
def send_redis_active_email(to_email,username,token):
    subject = '天天生鲜'
    message = ''
    sender = settings.EMAIL_FROM
    receiver = [to_email]
    html_message = '<h1>%s,欢迎使用天天生鲜,您已成为我们的用户</h1>请点击下面的链接激活用户<br/><a href="http://127.0.0.1:8000/user/active/%s">http://127.0.0.1:8000/user/active/%s</a>' \
                   % (username, token, token)
    send_mail(subject, message, sender, receiver, html_message=html_message)
    time.sleep(5)